﻿@using PNProject
@using PNProject.EF;
@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Layout1.cshtml";
    int active = Convert.ToInt16(ViewData["page-active"]);
    int total = (int)(ViewData["page-total"]);
    int pc = (int)(ViewData["page-pc"]);
    List<int> listPage = (List<int>)(ViewData["page-list"]);
    List<News> news = (List<News>)(ViewData["news"]);
    int last = 1;
    if (listPage.Count > 1)
    {
        last = listPage.ElementAt(listPage.Count - 1);
    }
    bool lang = (bool)(ViewData["lang"]);
    string langText = lang ? "" : "en-US/";
}
<div class="tebox">
    @foreach (var item in news)
    {
        string avatar = string.IsNullOrEmpty(item.Avatar) ? "/Images/Default-img.jpg" : item.Avatar;
        string xem = lang ? " Chi tiết" : " Detail";
        <div class="boxNe">            
            <ul>
                <li class="pic"><a href="/@string.Concat(langText, "news/detail/", item.TLink)">
                    <img src="@avatar" alt="" /></a></li>
                <li class="tit"><a href="/@string.Concat(langText, "news/detail/", item.TLink)">@item.Title</a></li>
                <li class="con"><span>@item.Short<a href="/@string.Concat(langText, "news/detail/", item.TLink)">@xem</a></span></li>
            </ul>
        </div>
    }

    
   
</div>
    <div class="pageT">
        <ul>
            <li><a href="/@string.Concat(langText,"news/index?p=1")">Trang đầu</a></li>
            @foreach (var item in listPage)
            {
                if (item == active)
                {
                     <li class="active"><a href="/@string.Concat(langText, "news/index?p=", item.ToString())">@item.ToString()</a></li>
                }
                else
                {
                    <li><a href="/@string.Concat(langText, "news/index?p=", item.ToString())">@item.ToString()</a></li>
                }
            }
            @if (last < pc)
            {
            <li><a href="/@string.Concat(langText, "news/index?p=", (last+1).ToString())">...</a></li>
            <li><a href="#"><img src="/images/icon-14.png" alt="" /></a></li>
            }
            <li><a href="/@string.Concat(langText, "news/index?p=", pc.ToString())">Trang cuối</a></li>
        </ul>
    </div>
<script type="text/javascript">
    $(document).ready(function () {
        $(".titlesub p").empty();
        var lang = document.URL.indexOf("en-US") < 0 ? true : false;
        if (lang) {
            $(".titlesub p").append("Tin tức & sự kiện");
            $("#ulink_home a").append("Trang chủ");
            $("#ulink_child a").append("Tin tức & sự kiện");
            $("#ulink_child a").attr("href", "/News");
        }
        else {
            $(".titlesub p").append("News & Events");
            $("#ulink_home a").append("Home");
            $("#ulink_home a").attr("href", "/en-US/home");
            $("#ulink_child a").append("News & Events");
            $("#ulink_child a").attr("href", "/en-US/News");
        }
    });
</script>